<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<TITLE>选择机构</TITLE>
<script type="text/javascript" language="JavaScript" src="../script/common.js"></script>
<script type="text/javascript" language="JavaScript">
	var urlPara = {
		selOne : null,					//选择一个机构	
		orgId : null,					//机构id
		onlyChildren : null,			//只查询下级机构
		orgLevel : null,				//查询那个等级的机构
		rangeLevel : null,				//查询到哪个等级的机构
		isStation : null,				//选择加油站
		isDeposit : null,				//充值点
		isGiftLocation : null,			//兑奖点
		qtTitle : null					//列表title
		
	}
	var qt = {}
	function load(){
		//取url中的参数
		for (prop in urlPara){
			var c = urlPara[prop];
			if (typeof c == "function") continue;
			urlPara[prop] = getPara(prop)
		}
		
		var usePage = getPara("usePage");					//页面名称
		var sqlName = "sel_orglist";
		if (usePage == "eps_manage")
			sqlName = "sel_not_eps_station";
			
		var columns = []
		var obj = {type:urlPara.selOne?"radio":"checkbox"}
		columns[0] = obj
		var cOrg = Common.cOrg();
		if (urlPara.orgId){
			if (urlPara.orgId != cOrg.id){
				var result = DWR.syncCall("partyService.getOrganization", urlPara.orgId)
				cOrg = result.organization;
			}
		}
		setOrg(cOrg)
		createTable(sqlName, "searchForm", "datalist", columns);
	}
	function createTable(sqlName,formId,divId,columns){
		qt = new QueryTable(sqlName, formId, divId, columns, {
			paramFunc:function(){
				var params = Common.getValues(formId);
				params = CardMgnt.merge(params,urlPara);
				return params;
			},
			displayBar:"none"
		});
		qt.showTable();
	}
	function setOrg(v){
		if (!v) return;
		searchForm.reset()
		if (v.orgLevel != Constants.ORG_LEVEL_HQ)
			searchForm.parentOrg.value = v.id
		searchForm.parentLevel.value = v.orgLevel
		searchForm.parentName.value = v.name
	}
	function onSave(){
		var result;
		if (urlPara.selOne){
			var r = qt.getRadioValue(true)
			if (!r){showWarning("请选择一个机构!");return;}
			result = {id:r[0],uniqueId:r[1],name:r[2]}
		}else{
			var list = qt.getBoxValue(true)
			if (!list||list.length<1){showWarning("至少选择一个机构!");return;}
			result = []
			for (var i=0;i<list.length;i++){
				var o = list[i]
				result.push({id:o[0],uniqueId:o[1],name:o[2]})
			}
		}
		dialogBackValue(result);
	}
	function selOrgan(){
		SystemMgnt.selOrg(setOrg,{id:urlPara.orgId})
	}
	</script>
	</HEAD>
<BODY class="body" onload='load()'>
	<div class="searchForm">
		<form id="searchForm" name="searchForm">
			<input type="hidden" name="parentOrg">
			<input type="hidden" name="parentLevel">
			<table cellSpacing="0" cellPadding="4" width="100%" border="0">
				<tr>
					<td>
						<label>上级机构</label>
						<input type="text" name="parentName" maxlength="20" readonly class="readonly"><a class="orga" href="#" onclick="selOrgan();">&nbsp;&nbsp;</a>
					</td>
					<td>
						<label>机构名称</label>
						<input type="text" name="name" maxlength="20">
					</td>
					<td><button type="button" onclick="qt.showTable()">查 询</button></td>
				</tr>
			</table>
		</form>
	</div>
	<div id="datalist"></div>
</BODY>
</HTML>
